﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SoftwareConsulting.BI11.Studio.Core.Project;
using SoftwareConsulting.BI11.Studio.Core.Project.SituationsHierarchy;
using SoftwareConsulting.BI11.Studio.Core.Project.SituationsHierarchy.RulesContainers;
using SoftwareConsulting.BI11.Studio.InternalServices;

namespace SoftwareConsulting.BI11.Studio.UI.ProjectExplorer.LogicalInferenceMechanism
{
    /// <summary>
    /// Класс формы просмотра результатов прохождения по контейнеру правил
    /// </summary>
    public partial class RulesContainerExecutingLogDialog : RestorableForm
    {
        private ProjectDescriptor _curProject; //для связи с проектом
        private Guid _owningCharacteristicId; //идентификатор характеристики-контейнера правил

        /// <summary>
        /// Геттер контейнера правил
        /// </summary>
        private RulesContainer RulesContainer
        {
            get
            {
                return _curProject.GetRulesContainerById((Guid)(_curProject.GetCharacteristicById(_owningCharacteristicId).ExpectedValue));
            }
        }

        public RulesContainerExecutingLogDialog(ProjectDescriptor currentProject, Characteristic owningCharacteristic)
        {
            _curProject = currentProject;
            _owningCharacteristicId = owningCharacteristic.Id;
            InitializeComponent();
        }

        /// <summary>
        /// Заполнение лога прохождения контейнера правил
        /// </summary>
        private void FillRulesContainer()
        {
            Text = Text + _curProject.GetItemById(_owningCharacteristicId).Name;
            int c = RulesContainer.RulesInConsiderationCount();
            for (int i = 0; i < c; i++)
            {
                SoftwareConsulting.BI11.Studio.Core.Project.SituationsHierarchy.RulesContainers.Rule r = RulesContainer.GetRuleByConsiderationOrder(i);
                ListBox.ObjectCollection rows = RulesBox.Items;                
                rows.AddRange(r.ToString().ToArray());
                rows.Add(string.Empty);
            }
        }

        private void RulesContainerExecutingLogDialog_Load(object sender, EventArgs e)
        {
            FillRulesContainer();
        }
    }
}
